import {
  compileAttr
} from "./compile";

/**
 * 负责属性更新
 * @param {*} vm 实例对象
 * @param {*} key 枚举data方法返回的对象的每一个属性名
 */
export function attrUpdate(vm, key) {
  const _stylePool = vm.$stylePool;
  /**
   * console.log(vm.$stylePool):
   * Map(4) {
   *   {div.box.show.danger => {type: "class", expression: "['box',isShow?'show':'',hasError?'danger':'']"}}, 
   *   {h1 => {type: "style", expression: "[titleStyle,{display:titleShow?'block':'none'}]"}}, 
   *   {h2 => {type: "style", expression: "{display:titleShow?'block':'none',color:subTitleColor,fontSize:'20px'}"}}, 
   *   {p.danger.big => {type: "class", expression: "{danger:hasError,big:isContentBig}"}}
   * }
   */

  //枚举_stylePool
  for (let [k, v] of _stylePool) {
    //console.log(k); 节点
    //div.box.show.danger / h1 / h2 / p.danger.big

    // console.log(v);
    //{"type": "class", "expression": "['box',isShow?'show':'',hasError?'danger':'']"}

    //包含key
    if (v.expression.indexOf(key) !== -1) {
      // compileAttr(vm, el, name, value)
      compileAttr(vm, k, v.type, v.expression);
    }
  }

}